package cn.yll.db.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


/**
 * bean 配置
 * @author yangll
 */
@Component
public class BeanConfig {

    /**
     * 配置mybatis插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {

        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        //设置最大分页条数200
        paginationInnerInterceptor.setMaxLimit(200L);
        //配置分页插件
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        //防止全表更新和删除插件
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        return interceptor;
    }

    /**
     * 注意：分布式事务组件seata暂不支持mybaits-plus的saveBatch()批量插入方法!!!!!!
     * 下面的sql批量插入方法是支持批量回滚的
     * 真实mysql批量插入 insert table_name() values (),(),()
     */
    @Bean
    public MySqlInjector mySqlInjector() {
        return new MySqlInjector();
    }
}
